package com.quizzer.web.controller.question;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.quizzer.system.dto.question.subject.SubjectAddDto;
import com.quizzer.system.dto.question.subject.SubjectOutputDto;
import com.quizzer.system.dto.question.subject.SubjectQueryDto;
import com.quizzer.system.dto.question.subject.SubjectUpdateDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.quizzer.common.annotation.Log;
import com.quizzer.common.core.controller.BaseController;
import com.quizzer.common.core.domain.AjaxResult;
import com.quizzer.common.enums.BusinessType;
import com.quizzer.system.domain.Subject;
import com.quizzer.system.service.ISubjectService;
import com.quizzer.common.utils.poi.ExcelUtil;
import com.quizzer.common.core.page.TableDataInfo;

/**
 * 大类别Controller
 *
 * @author ruoyi
 * @date 2025-10-07
 */
@Api(tags = "大类别接口")
@RestController
@RequestMapping("/question/subject")
public class SubjectController extends BaseController
{
    @Autowired
    private ISubjectService subjectService;

    /**
     * 查询大类别列表
     */
    @ApiOperation("查询大类别列表")
    @PreAuthorize("@ss.hasPermi('question:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(SubjectQueryDto subject)
    {
        startPage();
        List<SubjectOutputDto> list = subjectService.selectSubjectList(subject);
        return getDataTable(list);
    }

    /**
     * 导出大类别列表
     */
//    @ApiOperation("导出大类别列表")
//    @PreAuthorize("@ss.hasPermi('question:subject:export')")
//    @Log(title = "大类别", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Subject subject)
//    {
//        List<Subject> list = subjectService.selectSubjectList(subject);
//        ExcelUtil<Subject> util = new ExcelUtil<Subject>(Subject.class);
//        util.exportExcel(response, list, "大类别数据");
//    }

    /**
     * 获取大类别详细信息
     */
    @ApiOperation("获取大类别详细信息")
    @PreAuthorize("@ss.hasPermi('question:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(subjectService.selectSubjectById(id));
    }

    /**
     * 新增大类别
     */
    @ApiOperation("新增大类别")
    @PreAuthorize("@ss.hasPermi('question:subject:add')")
    @Log(title = "大类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SubjectAddDto subject)
    {
        return toAjax(subjectService.insertSubject(subject));
    }

    /**
     * 修改大类别
     */
    @ApiOperation("修改大类别")
    @PreAuthorize("@ss.hasPermi('question:subject:edit')")
    @Log(title = "大类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SubjectUpdateDto subject)
    {
        return toAjax(subjectService.updateSubject(subject));
    }

    /**
     * 删除大类别
     */
    @ApiOperation("删除大类别")
    @PreAuthorize("@ss.hasPermi('question:subject:remove')")
    @Log(title = "大类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(subjectService.deleteSubjectByIds(ids));
    }
}
